﻿using System;
using System.Text;
using AppCommon;
using Controller;

public partial class Modules_MenuControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindMenuTourtn();
            BindMenuTournn();
            BindMenuTourdocdao();
            BindMenuTourletet();
            BindSubDichvu();
            BindSubMedia();
            // Quang cao
            BindQuangCao(Constants.QC1);
        }
    }

    public void BindMenuTourtn()
    {
        var idtourtn = GetIdTourtrongnuoc();
        var controller = new VYC03Controller();
        var model = controller.GetByIdLoaiTour(idtourtn);
        if (model.Count > 0)
        {
            repeaterMenuTtn.DataSource = model;
            repeaterMenuTtn.DataBind();
        }
    }

    public void BindMenuTournn()
    {
        var idtourtn = GetIdTournuocngoai();
        var controller = new VYC03Controller();
        var model = controller.GetByIdLoaiTour(idtourtn);
        if (model.Count > 0)
        {
            repeaterMenuTnn.DataSource = model;
            repeaterMenuTnn.DataBind();
        }
    }

    public void BindMenuTourdocdao()
    {
        var idtourtn = GetIdTourdocdao();
        var controller = new VYC03Controller();
        var model = controller.GetByIdLoaiTour(idtourtn);
        if (model.Count > 0)
        {
            repeaterMenuTdd.DataSource = model;
            repeaterMenuTdd.DataBind();
        }
    }

    public void BindMenuTourletet()
    {
        var idtourtn = GetIdTourletet();
        var controller = new VYC03Controller();
        var model = controller.GetByIdLoaiTour(idtourtn);
        if (model.Count > 0)
        {
            repeaterMenutlt.DataSource = model;
            repeaterMenutlt.DataBind();
        }
    }

    public void BindSubDichvu()
    {
        int idLoaiDv = GetIdLoaiDiVu();
        var controller = new VYC05Controller();
        var model = controller.GetByIdLoaiChuyenMuc(idLoaiDv);

        if (model.Count > 0)
        {
            repeaterDivu.DataSource = model;
            repeaterDivu.DataBind();
        }
    }

    public void BindSubMedia()
    {
        int idLoaiDv = GetIdLoaiMedia();
        var controller = new VYC05Controller();
        var model = controller.GetByIdLoaiChuyenMuc(idLoaiDv);

        if (model.Count > 0)
        {
            repeaterMedia.DataSource = model;
            repeaterMedia.DataBind();
        }
    }

    public int GetIdLoaiMedia()
    {
        var controller = new VYC04Controller();
        var model = controller.GetByUniqueId(AppCommon.Common.ConvertToUnSign(Constants.CM_MEDIA));
        return model.Count > 0 ? model[0].Id : 0;
    }

    public int GetIdLoaiDiVu()
    {
        var controller = new VYC04Controller();
        var model = controller.GetByUniqueId(AppCommon.Common.ConvertToUnSign(Constants.CM_DICHVU));
        return model.Count > 0 ? model[0].Id : 0;
    }

    public int GetIdTournuocngoai()
    {
        var uniqueId = AppCommon.Common.ConvertToUnSign(Constants.TITLE_TOUR_NUOCNGOAI);
        var controller = new VYC02Controller();
        var model = controller.GetByUniqueId(uniqueId);
        if (model.Count > 0)
            return model[0].Id;
        return 0;
    }

    public int GetIdTourtrongnuoc()
    {
        var uniqueId = AppCommon.Common.ConvertToUnSign(Constants.TITLE_TOUR_TRONGNUOC);
        var controller = new VYC02Controller();
        var model = controller.GetByUniqueId(uniqueId);
        if (model.Count > 0)
            return model[0].Id;
        return 0;
    }

    public int GetIdTourdocdao()
    {
        var uniqueId = AppCommon.Common.ConvertToUnSign(Constants.TITLE_TOUR_DOCDAO);
        var controller = new VYC02Controller();
        var model = controller.GetByUniqueId(uniqueId);
        if (model.Count > 0)
            return model[0].Id;
        return 0;
    }

    public int GetIdTourletet()
    {
        var uniqueId = AppCommon.Common.ConvertToUnSign(Constants.TITLE_TOUR_LETET);
        var controller = new VYC02Controller();
        var model = controller.GetByUniqueId(uniqueId);
        if (model.Count > 0)
            return model[0].Id;
        return 0;
    }

    public string ReturnListTourDiemDen(int id)
    {
        var sb = new StringBuilder();
        var controller = new VYC0301Controller();
        var model = controller.GetByIdSubLoaiTour(id);
        if (model.Count > 0)
        {
            foreach (var i in model)
            {
                sb.Append("<li><a href=\"#\">"+ i.Ten +"</a></li>");
            }
        }
        return sb.ToString();
    }

    public void BindQuangCao(string uniqueid)
    {
        var controller = new VYC05Controller();
        var model = controller.GetByUniqueId(uniqueid);

        // Get quang cao 1
        if (model.Count > 0)
        {
            var controller1 = new VYC06Controller();
            var model1 = controller1.GetBySubLoaiCm(model[0].Id, 1);

            // Set link and image
            linkQuangcao.NavigateUrl = model1[0].LienKet;
            imgQuangcao.ImageUrl = Constants.UPLOAD_TINTUC + model1[0].AnhDaiDien;
            imgQuangcao.AlternateText = model1[0].TieuDe;
            imgQuangcao.ToolTip = model1[0].TieuDe;

        }
    }
}